define(function(require, exports, module) {
    var ALL = require("../../common/all"),
        CONFIG = ALL.CONFIG,
        METHOD = ALL.METHOD,
        Dialog = ALL.Dialog,
        Init = ALL.Init;

    var _Dialog = new Dialog({
        title : "提示",
        content : "<p></p>",
        text4Btn: ["确定"],
        class4Btn: [""]
    });


    var _vm = Init.initVue({
        data : {
            check: {},
            in_file : '',
            out_file : '',
            res : {
                type : 1,
                plan_name : '',
                out_no: '',
                in_no : '',
                col_id : '',
                price : '',
                cnt : '',
                out_fee : '',
                in_fee : '',
            }
        },
        methods: {
            submit : function() {

                this.check.$valid();
                flag = this.check.flag;

                if (!flag) {
                    return;
                }

                _vm.res.out_fee = _vm.out_fee;
                _vm.res.in_fee = _vm.in_fee;

                // new FormData
                var fd = new FormData();
                fd.append("data", JSON.stringify(_vm.res));
                if (_vm.res.type == 2) {
                    fd.append("file", _vm.in_file);
                }

                METHOD.loading.show();
                METHOD.ajax("transfer/plan/add",fd,{type : 'post',upload : true}).done(function(json){
                    METHOD.loading.hide();
                    if (_vm.res.type == 2) {
                        _Dialog.changeCfg({content : "<p>" + json.msg + "</p>"});
                        _Dialog.showUI(function() {
                            _vm.checkAgain();
                            this.hideUI();
                        });
                    } else {
                        _vm.checkAgain();
                    }
                }).fail(function(){
                    METHOD.loading.hide();
                })
            },
            checkAgain : function() {
                METHOD.alert("操作成功").done(function(){
                    window.location.href = "../trade/transfer.html";
                });
            },
            uploadFile : function(e, name) {
                var files = e.target.files,
                    file = files[0];

                if (files.length == 0 ) return;

                if (!/^.+\.(xls)|(xlsx)|(csv)$/i.test(file.name)) {
                    METHOD.alert("文件格式有误，请重新导入");
                } else {
                    _vm[name] = file;
                }
            }
        },
        computed: {
            fee: function() {
                var p = this.res.price || 0,
                    cnt = this.res.cnt || 0,
                    fee;

                    fee = parseFloat(p) * parseFloat(cnt) * 0.003;

                return fee.toFixed(2);
            },
            out_fee: function() {
                return this.fee;
            },
            in_fee: function() {
                return this.fee;
            }
        }
    });

});

